<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书管理</title>
<link type="text/css" rel="stylesheet" href="../../static/css/style.css" >
	<script src="../../Script/jquery.js"></script>
	<script src="../../Script/axios.js"></script>
	<script type="text/javascript">
		$(function () {
			axios({
				method:"get",
				url:"http://localhost:8080/library/bookShowServlet"
			}).then(function (resp) {
				var tableData="<tr>\n" +
						"\t\t\t\t<td>序号</td>\n" +
						"\t\t\t\t<td>名称</td>\n" +
						"\t\t\t\t<td>价格</td>\n" +
						"\t\t\t\t<td>作者</td>\n" +
						"\t\t\t\t<td>销量</td>\n" +
						"\t\t\t\t<td>库存</td>\n" +
						"\t\t\t\t<td colspan=\"2\">操作</td>\n" +
						"\t\t\t</tr>"
				for(let i = 0; i < resp.data.length; i++) {
					let book = resp.data[i];
					tableData+="<tr>\n" +
							"\t\t\t\t<td><input type=\"hidden\" value=\""+book.id+"\">"+(i+1)+"</td>\n" +
							"\t\t\t\t<td>"+book.name+"</td>\n" +
							"\t\t\t\t<td>"+book.price+"</td>\n" +
							"\t\t\t\t<td>"+book.author+"</td>\n" +
							"\t\t\t\t<td>"+book.sales+"</td>\n" +
							"\t\t\t\t<td>"+book.stock+"</td>\n" +
							"\t\t\t\t<td><a href=\"http://localhost:8080/library/bookSessionServlet?id="+book.id+"\"><button class=\"update\">修改</button></a></td>\n" +
							"\t\t\t\t<td><a href=\"http://localhost:8080/library/bookDeleteServlet?id="+book.id+"\"><input type=\"button\" value=\"删除\" class=\"delete\"></a></td>\n" +
							"\t\t\t</tr>"
				}
				tableData+="<tr>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td></td>\n" +
						"\t\t\t\t<td><a href=\"book_add.html\">添加图书</a></td>\n" +
						"\t\t\t</tr>"
				$("#bookTable").html(tableData)
			})

			$(document).on('click', '.delete',function() {
				var _this = this;
				return confirm("确定要删除此项?")
			});
		})


	</script>
</head>
<body>
	
	<div id="header">
			<img class="logo_img" alt="" src="../../static/img/logo.png" >
			<span class="wel_word">图书管理系统</span>
			<div>
				<a href="book_manager.html">图书管理</a>
				<a href="../../index.html">返回首页</a>
			</div>
	</div>
	
	<div id="main">
		<table id="bookTable">
			<tr>
				<td>序号</td>
				<td>名称</td>
				<td>价格</td>
				<td>作者</td>
				<td>销量</td>
				<td>库存</td>
				<td colspan="2">操作</td>
			</tr>
			
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td><a href="book_add.html">添加图书</a></td>
			</tr>	
		</table>
	</div>
	
	<div id="bottom">
		<span>
			图书管理系统.suo &copy;2022
		</span>
	</div>
</body>
</html>